package TI;

import java.util.ArrayList;
import java.util.List;

import org.mockito.verification.VerificationMode;

import Exceptions.NotEnoughStockException;
import Exceptions.ProductSalesPriceNeverSetException;
import Magnitudes.Money;
import Magnitudes.Pesos;
import Products.Presentation;

public class BranchOffice {
	
	
	private Address address;
	private List<Storehouse> storeHouses;
	private List<Sale> sales;
	private List<Offer> offers;
	private Systemo headquarter;
	private Money cash;
	
	
	
	

	public BranchOffice(Address anAddress, Systemo system) {
		this.address = anAddress;
		this.headquarter = system;
		this.storeHouses = new ArrayList<Storehouse>();
		this.sales = new ArrayList<Sale>();
		this.offers = new ArrayList<Offer>();
		this.cash = new Pesos(1000);
	}


	public void addOffer(Offer offer){
		this.offers.add(offer);
		this.headquarter.notifyOffer(offer);
	}

	public List<Sale> getSales() {		
		return this.sales;
	}


	public Money getCash() {		
		return this.cash;
	}





	public List<Storehouse> getStorehouses() {	
		return this.storeHouses;
	}





	public void associateStorehouse(Storehouse storehouse) {
		this.storeHouses.add(storehouse);
	}




	public void addCustomer(ParticularCustomer customer) {
		this.headquarter.addCustomer(customer);
	}





	public int checkAvailability(Presentation presentation){
		int total = 0;
		for(Storehouse store: storeHouses){
			if(store.isAvailable(presentation)){
				total = total + (store.currentStock(presentation));
			}
		}		
		return total;
	}





	public void receivePresentations(Presentation presentation, int cant, Pesos pesos) {
		this.storeHouses.get(0).receive(presentation, cant);
	}




	public void registerQuickBuy(Customer customerToTest, List<Presentation> products) throws ProductSalesPriceNeverSetException {
		this.sales.add(new QuickSale(products, this, customerToTest));
		Pesos cashe = new Pesos(0); 
		for(Presentation presentation: products){
			Pesos current = (Pesos) presentation.getUnitSalesPrice();
			cashe = cashe.add(current);
		}
		this.cash = cashe.add(cash);
	}




	public void returnProduct(ParticularCustomer particularCustomer,
			Presentation presentation) throws ProductSalesPriceNeverSetException {
		this.storeHouses.get(0).receive(presentation, 1);
		particularCustomer.setCurrentAccountAmount(presentation.getUnitSalesPrice());
	}




	public Address getAddress() {
		return this.address;
	}

	public void removeMailSuscriptionFor(ParticularCustomer aCustomer){
		this.headquarter.removeMailSuscriptionFor(aCustomer);
	}


		
	
	
	
	
	
	
	
	
	
	

}
